<template>
	<view class="content">
		<view class="header" >
			<image src="/static/image/index_head.png" mode="" style="width: 750rpx;"></image>
		</view>
		<view class="menu">
			<view class="menu-item flex" @click="userLogin('user_form')">
				<image src="/static/image/icon_user.png" mode=""></image>
				<view>完善基础信息</view>
				<image v-if="  pefect_time != null " src="/static/image/icon/icon_success.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
				<image v-if="  pefect_time == null " src="/static/image/icon/icon_error.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
			</view>
			<view class="menu-item flex" @click="userLogin('judge_sign')">
				<image src="/static/image/icon_contract.png" mode=""></image>
				<view>签署试岗协议</view>
				<image v-if="  sign_time != null " src="/static/image/icon/icon_success.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
				<image v-if="  sign_time == null " src="/static/image/icon/icon_error.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
			</view>
			<view class="menu-item flex" @click="userLogin('judge_attach')">
				<image src="/static/image/icon/upload1.png" mode=""></image>
				<view>上传附件信息</view>
				<image v-if="  attach_time != null " src="/static/image/icon/icon_success.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
				<image v-if="  attach_time == null " src="/static/image/icon/icon_error.png" mode="" style="width: 70rpx;height: 70rpx;"></image>
			</view>
		</view>
		<telTest ref="telTest" @close="telClose()"></telTest>
		<yfx-tooltip ref="tooltip"></yfx-tooltip>
		<zero-loading v-if="loading == true" type="gear" mask="true" maskOpacity="0.3"></zero-loading>
	</view>
	
</template>

<script>
	import uniPopup from '@/components/uniapp-components/uni-popup/uni-popup.vue';
	import noData from '@/components/ben-components/notData/notData.vue';
	import telTest from'@/components/ben-components/tel/tel-test.vue';
	
	
	
	export default {
		onShareAppMessage() {
			return {
				title: '小微入职助手',//分享标题
				// path: 'xxx', // 可选，如果希望点击进去是小程序的某个页面
				imageUrl: '', // 分享图片地址
				success: function(res) {

				},
				fail: function(err) {

				}
			};
		},
		components: {
			uniPopup,
			noData,
			telTest,
		},
		data(){
			return{
				loading         : false,  
				pefect_time     : null,
				sign_time 		: null,
				attach_time 	: null,
				charge_confirm_time 	: null,
				hr_confirm_time 	: null,
				contract_status : '',
				status_title    : '',
				sign_id         : 2,
			}
		},
		onShow(){  
			// 如果是提交状态返回isRefresh=1，才刷新页面，从详情过来无需刷新
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if(currPage.__data__.isRefresh){
				this.userLogin();
				// 每一次需要清除，否则会参数会缓存
				currPage.__data__.isRefresh=false
			}
		},
		//监听页面显示。页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面
		onShow() {
			this.$refs.telTest.close();
			this.getUserInfo();	
		},
		onLoad(){
			this.userLogin();
		},
		methods:{
			telClose(){
				this.getUserInfo();
			},
			userform(){
				if( this.contract_status == 'LEAVE'){
					this.$refs.tooltip.open({
						msg: '提示',//标题
						content: '你已离职,操作失败!',//提示内容
						showCancel: false//不显示取消按钮
					})
				}else{
					this.linkMy('/pages/index/info-form')
				}
			
			},
			attach(){
				if( this.sign_time == null ){
					//显示弹窗 
					this.$refs.tooltip.open({
						msg: '错误',//标题
						content: '请先完善基础信息并签署试岗协议',//提示内容
						showCancel: false//不显示取消按钮
					})
				}else{
					this.linkMy('/pages/index/uploadPic')
				}
			},
			sign(){
				
				if( this.pefect_time == null ){
					this.$refs.tooltip.open({
						msg: "错误",
						content:"请先完善基础信息",
						showCancel: false//不显示取消按钮
					})	 
				}else if( this.sign_time != null ){
					if(this.charge_confirm_time == null){
						this.$refs.tooltip.open({
							msg: "重复签名提醒",
							content:"你已签署过试岗协议，是否重新签署",
							 confirm: () => {
								 uni.navigateTo({
								 	url: '/pages/sign/trial-job?sign_id='+this.sign_id
								})
							 } 
						})	 
					}else{
						if( this.contract_status == 'LEAVE'){
							var msg = '你已离职,操作失败!'
						}else{
							var msg = '已初步审核,无法重新签署!'
						}
						this.$refs.tooltip.open({
							msg: '提示',//标题
							content: msg,//提示内容
							showCancel: false//不显示取消按钮
						})
					}
				}else{
					this.linkMy('/pages/sign/trial-job?sign_id='+this.sign_id)
				}
			},
			linkMy(url){
				if( this.contract_status == 'LEAVE'){
					this.$refs.tooltip.open({
						msg: '提示',//标题
						content: '你已离职,操作失败!',//提示内容
						showCancel: false//不显示取消按钮
					})
				}else{
					this.userLogin('link',url);
				}
			},
			// sendAjaxContract(){
			// 	this.getUserInfo();
			// },
			getUserInfo( type ) {
				let param = {};
				this.$http.getUser(param).then(res => {
					if (res.code == 1 && res.data) {
						this.contract_status   =  res.data.status;
						this.status_title      =  res.data.status_text;
						this.pefect_time       =  res.data.pefect_time;
						this.attach_time       =  res.data.attach_time;
						this.charge_confirm_time = res.data.charge_confirm_time;
						this.hr_confirm_time   = res.data.hr_confirm_time;
						this.sign_time         =  res.data.sign_time;
						if(res.data.area == 'jn' || res.data.area == 'tj'){
							this.sign_id = 3;
						}
					
						uni.setStorageSync('mobile',res.data.mobile?res.data.mobile:'')
						if(type == 'judge_sign'){
							this.sign();
						}else if(type == 'judge_attach'){
							this.attach();
						}else if(type == 'user_form'){
							this.userform();
						}
					}else{
						// if(res.code == 401){
							// uni.removeStorageSync('token');
							 uni.removeStorageSync('mobile');
							 this.contract_status   =  '';
							 this.status_title      =  '';
							 this.pefect_time       =  null;
							 this.attach_time       =  null;
							 this.charge_confirm_time = null;
							 this.hr_confirm_time   = null;
							 this.sign_time         =  null;
						// }
						// this.$refs.tooltip.open({
						// 	msg: '提示',//标题
						// 	content: res.msg,//提示内容
						// 	showCancel: false//不显示取消按钮
						// })
					}
				});
			},
			userLogin(type,url){
				this.loading = true;
				var that = this;
				if (uni.getStorageSync('token') && 　uni.getStorageSync('mobile')) {
					this.loading = false;
					if(type == 'link'){
						uni.navigateTo({
							url
						})
					}else{
						this.getUserInfo(type);
					}
				} else {
					if(!uni.getStorageSync('token')){
						var code = '';
						uni.login({
							provider: 'weixin',
							success: function(logRes) {
								code = logRes.code;
							}
						});
						// 获取code
					
						uni.getUserProfile({
							desc: '作为展示',
							success: res => {
								let param = {
									code: code,
									iv: res.iv,
									encryptedData: res.encryptedData,
									rawData: res.rawData,
									signature: res.signature,
									nickname: res.userInfo.nickName,
									avatar: res.userInfo.avatarUrl,
								};
								that.$http.authorization(param).then(res => {
									uni.hideToast();
									this.loading = false;
									if (res.code == 1) {
										uni.setStorageSync('token', res.data.token);
										uni.setStorageSync('mobile',res.data.mobile?res.data.mobile:'')
										
										if(uni.getStorageSync('mobile')){
											this.mobile=uni.getStorageSync('mobile');
											
											if(type == 'link'){
												uni.navigateTo({
													url
												})
											}else{
												this.getUserInfo(type);
											}
										} else {
											this.$refs.telTest.open(url)
										}
										
									}
								});
							},
							fail: err => {
								this.loading = false;
								
								console.log('获取失败', err);
							}
						});
					} else{
						this.loading = false;
						// this.getUserInfo(type);
						// if( this.contract_status == 'LEAVE'){
						// 	this.$refs.tooltip.open({
						// 		msg: '提示',//标题
						// 		content: '你已离职,操作失败!',//提示内容
						// 		showCancel: false//不显示取消按钮
						// 	})
						// }else{
							this.$refs.telTest.open(url)
							
						// }
					}
					
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.header{
		width: 100%;
	}
	.menu{
		padding:20rpx;
		.menu-item{
			padding: 40rpx 100rpx;
			text-align: center;
			color: #fff;
			font-size: 35rpx;
			letter-spacing: 5rpx;
			align-items: center;
			
			background: linear-gradient(to right, #ffaa83, #ff6123);
			border-radius: 20rpx;
			margin: 20rpx;
			image{
				width: 100rpx;
				height: 100rpx;
				margin-right: 30rpx;
				padding: 6rpx;
			}
			&:nth-child(2){
				background: linear-gradient(to right, #FFD887, #FF9D27);
			}
		}
		
	}
</style>
